package com.pet_service.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.pet_service.util.CodeEnum;
import lombok.Getter;

/**
 * @author 邹全伸
 * @version 1.0
 * @date 2025-09-18 13:52
 */
@Getter
public enum TFosterOrderStatus implements CodeEnum {
    PENDING(0, "待寄养"),
    IN_PROGRESS(1, "寄养中"),
    COMPLETED(2, "已接回");

    @EnumValue
    private final int code;
    private final String desc;

    TFosterOrderStatus(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    // 添加这个方法用于序列化
    @JsonValue
    public int getCode() {
        return code;
    }

    // 添加这个方法用于反序列化
    @JsonCreator
    public static TFosterOrderStatus fromCode(Object code) {
        int codeValue;
        if (code instanceof String) {
            codeValue = Integer.parseInt((String) code);
        } else if (code instanceof Integer) {
            codeValue = (Integer) code;
        } else {
            throw new IllegalArgumentException("Unsupported code type: " + code.getClass());
        }

        for (TFosterOrderStatus status : TFosterOrderStatus.values()) {
            if (status.getCode() == codeValue) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown enum code: " + codeValue);
    }

    public String getDesc() { return desc; }
}
